<?php
error_reporting(55);

# вывод переменной
function print_pre($var) {
	echo '<pre>'.str_replace('&lt;?','',highlight_string('<?'.print_r($var,true),true)).'</pre>';
}

function print_sql_error($error,$sql) {
	global $mysql_debug_sql, $mysql_debug_sql_count;
	  
	preg_match('|the right syntax to use near \'(.*)\' at line|Uis',$error, $errors);
	if (!empty($errors)) {
		echo trim($errors[1]);
		//preg_replace('|'.$errors[1].'|Uis', 'wow', $sql);
	
		$sql=str_replace($errors[1], '<span style="border-bottom:1px dashed #da2f31;">'.$errors[1].'</span>', $sql);
		
	}
	?>
	<div style="background:#f4f4f4; border:1px solid #bbbbbb; color:#333333; padding:3px;">
	Error:<br>
	<span style="color:#da2f31; font-weight:bold"><?php echo $error;?></span>
	<br>
	Query:<br>
	<span style="color:#629525; font-weight:normal"><?php echo str_replace("\n",'<br />',$sql);?></span>
	<br />
	<button onclick="sql=document.getElementById('sql_debug_history_<?php echo $mysql_debug_sql_count;?>').style; if (sql.display=='block') sql.display='none'; else sql.display='block';  return false;">Показать историю запросов</button>
	<div id="sql_debug_history_<?php echo $mysql_debug_sql_count;?>" style="border:1px  solid #dddddd; background:#eeeeee; padding-left:10px; color:#444444; font-size:12px; display:none; display:none;">
	<?php
	foreach ($mysql_debug_sql as $k=>$sql) {
		echo ($k+1).':	'.$sql.'<br />';
	}
	?>
	</div>
	</div>
	<?php
}

$mysql_debug_sql=array();
$mysql_debug_sql_count=0;
function mysql_debug_add_sql($sql) {
	global $mysql_debug_sql,$mysql_debug_sql_count;
	$mysql_debug_sql[]=$sql;
	$mysql_debug_sql_count++;
}
define('mysql_debug', true);
?>